package com.my.study;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 创建自定义的线程工厂
 */
public class UserThreadFactory implements ThreadFactory {

    private String namePrefix;

    private final AtomicInteger nextId = new AtomicInteger(1);


    public UserThreadFactory(String whatFeatureOfGroup) {

        namePrefix = "UserThreadFactory's " + whatFeatureOfGroup + "-Worker";

    }

    @Override
    public Thread newThread(Runnable task) {
        String name = namePrefix + nextId.getAndIncrement();
        Thread thread = new Thread(null, task, name, 0);
        System.out.println("threadName is :  " + thread.getName());
        return null;
    }
}
